{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Watch the Getting Started Quick Start [Video](https://aka.ms/SK-Getting-Started-Notebook)\n",
    "\n",
    "> [!IMPORTANT]\n",
    "> You will need an [.Net 7 SDK](https://dotnet.microsoft.com/en-us/download) and [Polyglot](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.dotnet-interactive-vscode) to get started with this notebook using .Net Interactive\n",
    "\n",
    "**Step 1**: Import Semantic Kernel SDK from NuGet"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    }
   },
   "outputs": [],
   "source": [
    "// Import Semantic Kernel\n",
    "#r \"nuget: Microsoft.SemanticKernel, 0.12.207.1-preview\""
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Step 2**: Add your [Open AI Key](https://openai.com/api/) or [Azure Open AI Service key](https://learn.microsoft.com/azure/cognitive-services/openai/quickstart?pivots=programming-language-studio) key to run a function below and save your key in the configuration files for later use."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    }
   },
   "outputs": [],
   "source": [
    "// NOTE: When you run this section, you'll be prompted to enter your key\n",
    "\n",
    "#!import config/Settings.cs\n",
    "\n",
    "// Setup Open AI Configuration\n",
    "bool useAzureOpenAI = false;\n",
    "await Settings.AskAzureEndpoint(useAzureOpenAI);\n",
    "await Settings.AskModel(useAzureOpenAI);\n",
    "await Settings.AskApiKey(useAzureOpenAI);\n",
    "\n",
    "// Uncomment this if you are using the Open AI Service and have an Org ID\n",
    "// await Settings.AskOrg(useAzureOpenAI);"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Step 3**: Instantiate the Kernel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    }
   },
   "outputs": [],
   "source": [
    "using Microsoft.SemanticKernel;\n",
    "\n",
    "// Set Simple kernel instance\n",
    "IKernel kernel = KernelBuilder.Create();"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    }
   },
   "outputs": [],
   "source": [
    "// Configure AI backend used by the kernel\n",
    "var (useAzureOpenAI, model, azureEndpoint, apiKey, orgId) = Settings.LoadFromFile();\n",
    "if (useAzureOpenAI)\n",
    "    kernel.Config.AddAzureTextCompletionService(\"davinci\", model, azureEndpoint, apiKey);\n",
    "else\n",
    "    kernel.Config.AddOpenAITextCompletionService(\"davinci\", model, apiKey, orgId);"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Step 4**: Load and Run a Skill"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    }
   },
   "outputs": [],
   "source": [
    "using Microsoft.SemanticKernel.KernelExtensions;\n",
    "\n",
    "// Load the Skills Directory\n",
    "var skillsDirectory = Path.Combine(System.IO.Directory.GetCurrentDirectory(), \"..\", \"..\", \"skills\");\n",
    "\n",
    "// Load the FunSkill from the Skills Directory\n",
    "var skill = kernel.ImportSemanticSkillFromDirectory(skillsDirectory, \"FunSkill\");\n",
    "\n",
    "// Run the Function called Joke\n",
    "var result = await kernel.RunAsync(\"time travel to dinosaur age\", skill[\"Joke\"]);\n",
    "\n",
    "// Return the result to the Notebook\n",
    "Console.WriteLine(result);"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Next Steps**: You know the basics, let's try this in a sample app so you can learn the core concepts!\n",
    "\n",
    "Sample app learning examples:\n",
    "- [Simple chat summary](../../apps/chat-summary-webapp-react/README.md) (**Recommended**) – learn how basic semantic functions can be added to an app\n",
    "- [Book creator](../../apps/book-creator-webapp-react/README.md) – learn how Planner and chaining of semantic functions can be used in your app\n",
    "- [Authentication and APIs](../../dotnet/graph-api-skills/README.md) – learn how to connect to external API's with authentication while using Semantic Kernel\n",
    "- [GitHub repository Q&A](../../apps/github-qna-webapp-react/README.md) - Use embeddings and memory to store and query your data\n",
    "- [Copilot Chat](../../apps/copilot-chat-app/README.md) – Build your own chatbot based on Semantic Kernel"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".NET (C#)",
   "language": "C#",
   "name": ".net-csharp"
  },
  "language_info": {
   "name": "polyglot-notebook"
  },
  "polyglot_notebook": {
   "kernelInfo": {
    "defaultKernelName": "csharp",
    "items": [
     {
      "aliases": [],
      "name": "csharp"
     }
    ]
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
